//
//  LGLingyuanMangeViewController.m
//  ligenyun
//
//  Created by Mac on 2018/4/10.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGLingyuanMangeViewController.h"

#import "LGMineLingyuanMangeTableViewCell.h"
#import "LGAttentionLingyuanMangeTableViewCell.h"
#import "LGSiJiCreateViewController.h"
@interface LGLingyuanMangeViewController ()
@property(nonatomic, strong) UISegmentedControl                     *segement;
@end

@implementation LGLingyuanMangeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"陵园管理";
    [self configSubView];
    [self st_setRightItemWithImage:[UIImage imageNamed:@"纪念馆添加icon"]];
    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configSubView{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 20)];
    header.backgroundColor = self.tableView.backgroundColor;
    
    CGFloat segementWith = (UIScreenWidth - 40)/2;
    self.segement = [[UISegmentedControl alloc] initWithItems:@[@"我创建的陵园",@"我关注的陵园"]];
    self.segement.frame = CGRectMake(20, 15 + 0, segementWith * 2, 44);
    self.segement.tintColor = TM_redColor;
    self.segement.selectedSegmentIndex = 0;
    [self.segement setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} forState:UIControlStateSelected];
    [self.segement setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} forState:UIControlStateNormal];
    [self.segement addTarget:self action:@selector(onSelctedSegement:) forControlEvents:UIControlEventValueChanged];
    [header addSubview:self.segement];
    __weak typeof(self) weakSelf =  self;
    STButton * searchButton = [[STButton alloc] initWithFrame:CGRectMake(20, self.segement.bottom + 20, UIScreenWidth - 40, 44)
                                                     title:@"搜索"
                                                titleColor:SecendTextColor
                                                 titleFont:14
                                              cornerRadius:4
                                           backgroundColor:[UIColor whiteColor]
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"搜索"]];
    searchButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    searchButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [searchButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedSearchButton];
    }];
   
    [header addSubview:searchButton];
    
    header.height = searchButton.bottom + 20;
    self.tableView.tableHeaderView = header;
    
    [self.tableView registerClass:[LGMineLingyuanMangeTableViewCell class] forCellReuseIdentifier:@"mineCell"];
    [self.tableView registerClass:[LGAttentionLingyuanMangeTableViewCell class] forCellReuseIdentifier:@"attentionCell"];
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.segement.selectedSegmentIndex == 0) {
        return [LGMineLingyuanMangeTableViewCell cellHeight];
    }
    return [LGAttentionLingyuanMangeTableViewCell cellHeight];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    __weak typeof(self) weakSelf =  self;
    if (self.segement.selectedSegmentIndex == 0) {
        LGMineLingyuanMangeTableViewCell * cell = [self.tableView dequeueReusableCellWithIdentifier:@"mineCell"];
        [cell.mangeButton setClicAction:^(UIButton *sender) {
            [weakSelf onSelctedMangeButtonWithIndexPath:indexPath];
        }];
        [cell.delButton setClicAction:^(UIButton *sender) {
            [weakSelf onSelctedDelButtonWithIndexPath:indexPath];
        }];
        return cell;
    }
    LGAttentionLingyuanMangeTableViewCell * cell = [self.tableView dequeueReusableCellWithIdentifier:@"attentionCell"];
    [cell.baijiButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedBaijiButtonWithIndexPath:indexPath];
    }];
    [cell.cancleButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedCanleButtonWithIndexPath:indexPath];
    }];
    return cell;

}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}

#pragma mark --Action Method
- (void)st_rightBarAction:(id)sender{
    LGSiJiCreateViewController * vc = [LGSiJiCreateViewController new];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)onSelctedSegement:(UISegmentedControl*)sender{
    [self.tableView reloadData];
}
- (void)onSelctedSearchButton{
    
}
- (void)onSelctedMangeButtonWithIndexPath:(NSIndexPath*)indexPath{
    
}
- (void)onSelctedDelButtonWithIndexPath:(NSIndexPath*)indexPath{
    
}
- (void)onSelctedBaijiButtonWithIndexPath:(NSIndexPath*)indexPath{
    
}
- (void)onSelctedCanleButtonWithIndexPath:(NSIndexPath*)indexPath{
    
}
@end
